package demo03_auto;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by ztt on 2017/9/15.
 */

@Component
public class UserBean {

    private DeptBean deptBean;

    private AuthorityBean authorityBean;

    private OtherBean otherBean;

    @Autowired
    private RoleBean roleBean;

    //@Inject /** 报错 **/
    private InjectBean injectBean;

    /** 如果未找到匹配的bean，禁止报错的话，可将required设为true **/
    @Autowired(required = false)
    private NotBean notBean;

    /** 通过构造方法注入bean **/
    @Autowired
    public UserBean(DeptBean deptBean){
        this.deptBean=deptBean;
    }

    /** setter 方法  **/
    @Autowired
    public void setAuthorityBean(AuthorityBean authorityBean){
        this.authorityBean=authorityBean;
    }

    /** 其实任意方法都可以 **/
    @Autowired
    public void jdsof2034sjf(OtherBean otherBean){
        this.otherBean=otherBean;
    }

    public void getDept(){
        deptBean.getDept();
    }

    public void getRole(){
        roleBean.getRole();
    }

    public void getAuthority(){
        authorityBean.getAuthority();
    }

    public void other(){
        System.out.println("authorityBean："+authorityBean);
    }
}

class NotBean{

}

@Component
class InjectBean{

}
